#include "stdafx.h"
#include "Signal.h"
#include "../ConstStr/ConstStr.h"

using namespace Base::Sig;

namespace {

    // Make sure that the ID is unique.
    // If not, return 0.
    const void* check(const void* sigId)
    {
        typedef std::vector<const void*> IDs;

        static IDs kIDs;
        for (IDs::const_iterator it = kIDs.begin();
             it != kIDs.end(); ++it)
        {
            if (*it == sigId)
            {
                assert(false);
                return 0;
            }
        }

        kIDs.push_back(sigId);
        return sigId;
    }

}

// ----------------------------------------------------------------------------
// SigIdGenerator

SigIdGenerator::SigIdGenerator(const std::string& strId)
    : m_id(0)
{
    const void* id = Base::ConstStr::ConstStr::get()->string(strId);
    m_id = ::check(id);
    assert(m_id);
}

SigIdGenerator::~SigIdGenerator()
{
}

const void*
SigIdGenerator::value() const
{
    return m_id;
}

// ----------------------------------------------------------------------------
// Signal

Signal::Signal()
{
}

Signal::~Signal()
{
}

const void* 
Signal::typeId()
{
    assert(false);
    return 0;
}

const void*
Signal::id() const
{
    assert(false);
    return Signal::typeId();
}